package org.example.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 拷贝
 *
 * @author 欧阳劲驰
 * @since JDK1.8
 */
public class Demo4 {
    public static void main(String[] args) {
        //创建文件输入\输出流
        try (FileInputStream fileInputStream = new FileInputStream("demo.txt");
             FileOutputStream fileOutputStream = new FileOutputStream("demo1.txt")) {
            //获取输入\输出通道
            FileChannel inputChannel = fileInputStream.getChannel();
            FileChannel outputChannel = fileOutputStream.getChannel();
            //从输入\输出通道发送至输出\输入通道
            inputChannel.transferTo(0, inputChannel.size(), outputChannel);
//            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
